package com.baiyangtx.lingerweather.model;

import java.util.Calendar;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.baiyangtx.lingerweather.R;


/**
 * 
 * Just for test.
 * @author BaiyangTX
 *
 */
public class DefaultWeatherChartModel implements WeatherChartModel {

	// sunny
	public static final int WEATHER_SUNNY = R.drawable.sunny ;
	// rain
	public static final int WEATHER_LIGHT_RAIN = R.drawable.light_rain ;
	public static final int WEATHER_HEAVY_RAIN = R.drawable.heavy_rain ;
	public static final int WEATHER_HARD_RAIN = R.drawable.hard_rain ;
	// cloud
	public static final int WEATHER_CLOUD = R.drawable.cloudy ;
	public static final int WEATHER_OVERCAST = R.drawable.overcast ;
	// windy
	public static final int WEATHER_WINDY = R.drawable.windy ;
	// snow
	public static final int WEATHER_LIGHT_SNOW = R.drawable.light_snow ;
	public static final int WEATHER_HEAVY_SNOW = R.drawable.heavy_snow ;
	// fog
	public static final int WEATHER_FOG = R.drawable.fog ;
	
	
	
	
	private Context context ;
	
	private String txtToday = "今天" ;
	
	private String[] weekText = {"周日" , "周一" , "周二" , "周三" , "周四" , "周五" , "周六" } ;
	
	private String[] noonWeather = {  "多云" , "多云" , "多云" , "多云" , "多云" , "多云" } ;
	
	private String[] nightWeather = { "多云" , "多云" , "多云" , "多云" , "多云" , "多云"  } ;
	
	private int[] noonTemperature = { 3 ,  3 , 3 , 3 , 3 , 3  } ;
	
	private int[] nightTemperature = { 0 , 0 , 0 , 0 , 0 , 0 } ;
	
	
	
	
	
	
	
	
	
	
	
	protected final int days = 6 ;
	
	protected Calendar today ;
	
	public DefaultWeatherChartModel(Context context ) {
		this.context = context ;
	}
	
	
	public void setToday( Calendar today )
	{
		this.today = today ;
	}
	
	
	@Override
	public int getDaysNumber() {
		return days ;
	}

	@Override
	public String getDayOfWeek(int dayOfNext) {
		if( dayOfNext == 0 )
		{
			return txtToday ;
		}
		int index = (dayOfNext + today.get(Calendar.DAY_OF_WEEK ) )%7 ; 
		return weekText[index] ;
	}

	@Override
	public String getNoonWeatherText(int dayOfNext) {
		return noonWeather[dayOfNext];
	}

	@Override
	public Drawable getNoonWeatherDrawable(int dayOfNext) {
		Drawable weather = null ;
		int id = 0 ;
		switch( dayOfNext )
		{
		case 0 :
			id = WEATHER_CLOUD ;
			break ;
		case 1 :
			id = WEATHER_CLOUD ;
			break ;
		case 2 :
			id = WEATHER_CLOUD ;
			break ;
		case 3 :
			id = WEATHER_CLOUD ;
			break ;
		case 4 :
			id = WEATHER_CLOUD ;
			break ;
		case 5 :
			id = WEATHER_CLOUD ;
			break ;
		default :
			weather = null ;
			break ;
		}
		weather = context.getResources().getDrawable( id ) ;
		return weather ;
	}

	@Override
	public Drawable getNightWeatherDrawable(int dayOfNext) {	
		Drawable weather = null ;
		int id = 0 ;
		switch( dayOfNext )
		{
		case 0 :
			id = WEATHER_CLOUD ;
			break ;
		case 1 :
			id = WEATHER_CLOUD ;
			break ;
		case 2 :
			id = WEATHER_CLOUD ;
			break ;
		case 3 :
			id = WEATHER_CLOUD ;
			break ;
		case 4 :
			id = WEATHER_CLOUD ;
			break ;
		case 5 :
			id = WEATHER_CLOUD ;
			break ;
		default :
			weather = null ;
			break ;
		}
		weather = context.getResources().getDrawable( id ) ;
		return weather ;
	}

	@Override
	public String getNightWeatherText(int dayOfNext) {
		return nightWeather[dayOfNext ] ;
	}

	@SuppressLint("DefaultLocale")
	@Override
	public String getDate(int dayOfNext) {
		Calendar t = (Calendar) today.clone() ;
		t.roll(Calendar.DATE, dayOfNext) ;
		int month = t.get(Calendar.MONTH) + 1 ;
		int day = t.get( Calendar.DATE ) ;
		String date = String.format("%02d.%02d", month , day ) ;
		return date ;
	}

	@Override
	public Context getContext() {
		return context ;
	}


	@Override
	public int getHighestTemperature(int dayOfNext) {
		return noonTemperature[dayOfNext] ;
	}


	@Override
	public int getLowestTemperature(int dayOfNext) {
		return nightTemperature[dayOfNext] ;
	}

}
